home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE05 / PERFORM / UNITPERF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-22  |  5.6 KB  |  196 lines

  1. {$A+,B-,D-,F-,G+,I+,K+,L-,N+,P+,Q-,R-,S+,T+,V-,W-,X+,Y-}
  2. unit Unitperf;
  3.  
  4. interface
  5.  
  6. uses
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, StdCtrls, FileCtrl, Outline, DirOutln, Gauges, Grids;
  9.  
  10. type
  11.   TMainForm = class(TForm)
  12.     DriveComboBox1: TDriveComboBox;
  13.     DirectoryOutline1: TDirectoryOutline;
  14.     FileListBox1: TFileListBox;
  15.     Label1: TLabel;
  16.     ExitButton: TButton;
  17.     ViewButton: TButton;
  18.     RenameButton: TButton;
  19.     DeleteButton: TButton;
  20.     CopyButton: TButton;
  21.     Gauge1: TGauge;
  22.     UUEncodeButton: TButton;
  23.     UUDecodeButton: TButton;
  24.     Button1: TButton;
  25.     procedure DriveComboBox1Change(Sender: TObject);
  26.     procedure DirectoryOutline1Change(Sender: TObject);
  27.     procedure ExitButtonClick(Sender: TObject);
  28.     procedure ViewButtonClick(Sender: TObject);
  29.     procedure DeleteButtonClick(Sender: TObject);
  30.     procedure RenameButtonClick(Sender: TObject);
  31.     procedure UUEncodeButtonClick(Sender: TObject);
  32.     procedure Button1Click(Sender: TObject);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.   end;
  38.  
  39. var
  40.   MainForm: TMainForm;
  41.  
  42. implementation
  43. Uses Unit2, Unit3, FileCopy, UUCode;
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TMainForm.DriveComboBox1Change(Sender: TObject);
  48. begin
  49.   DirectoryOutLine1.Drive := DriveComboBox1.Drive
  50. end;
  51.  
  52. procedure TMainForm.DirectoryOutline1Change(Sender: TObject);
  53. begin
  54.   FileListBox1.Directory := DirectoryOutline1.Directory
  55. end;
  56.  
  57. procedure TMainForm.ExitButtonClick(Sender: TObject);
  58. begin
  59.   Close
  60. end;
  61.  
  62. procedure TMainForm.ViewButtonClick(Sender: TObject);
  63. begin
  64.   try
  65.     ViewerForm.Memo1.Lines.LoadFromFile(FileListBox1.FileName);
  66.     ViewerForm.Show
  67.   except
  68.     on E: Exception do
  69.       MessageDlg(E.Message, mtError, [mbOk], 0)
  70.   end
  71. end;
  72.  
  73. procedure TMainForm.DeleteButtonClick(Sender: TObject);
  74. var f: File;
  75.     Str: String;
  76. begin
  77.   if FileListBox1.FileName <> '' then
  78.   begin
  79.     FmtStr(Str,'Do you want to delete %s',[FileListBox1.FileName]);
  80.     if MessageDlg(Str, mtConfirmation, [mbYes,mbNo], 0) = mrYes then
  81.     try
  82.       try
  83.         System.Assign(f,FileListBox1.FileName);
  84.         Erase(f)
  85.       except
  86.         on E: Exception do
  87.           MessageDlg(E.Message, mtError, [mbOk], 0)
  88.       end;
  89.     finally
  90.       FileListBox1.Directory := '.';
  91.       FileListBox1.Directory := DirectoryOutLine1.Directory { rescan }
  92.     end
  93.     else
  94.       MessageDlg('No file deleted', mtInformation, [mbOk], 0)
  95.   end
  96.   else
  97.     MessageDlg('No file selected', mtError, [mbOk], 0)
  98. end;
  99.  
  100.   procedure CallBack(Position, Size: LongInt); export;
  101.   var Progress: LongInt;
  102.   begin
  103.     Progress := (Position * MainForm.Gauge1.MaxValue) div Size;
  104.     if MainForm.Gauge1.Progress <> Progress then { no unnecessary updates! }
  105.       MainForm.Gauge1.Progress := Progress
  106.   end {CallBack};
  107.  
  108. procedure TMainForm.RenameButtonClick(Sender: TObject);
  109. var CallBackProc: TCallBack;
  110. var f: File;
  111.     FileName: String;
  112.     Len: Byte absolute FileName;
  113. begin
  114.   if FileListBox1.FileName <> '' then
  115.   begin
  116.     FileNameDialog.OldFileName.Text := FileListBox1.FileName;
  117.     FileNameDialog.NewFileName.Text := FileListBox1.FileName;
  118.     if FileNameDialog.ShowModal <> idCancel then
  119.     begin
  120.       FileName := FileNameDialog.NewFileName.Text;
  121.       try
  122.         try
  123.           if Sender = RenameButton then
  124.           begin
  125.             System.Assign(f,FileListBox1.FileName);
  126.             System.Rename(f,FileName)
  127.           end
  128.           else { Sender = CopyButton }
  129.           begin
  130.             Gauge1.Progress := 0;
  131.             CallBackProc := CallBack;
  132.             FastFileCopy(FileListBox1.FileName,FileNameDialog.NewFileName.Text,
  133.                          CallBackProc)
  134.           end
  135.         except
  136.           on E: Exception do
  137.             MessageDlg(E.Message, mtError, [mbOk], 0)
  138.         end;
  139.       finally
  140.         FileListBox1.Directory := '.';
  141.         FileListBox1.Directory := DirectoryOutLine1.Directory; { rescan }
  142.         { TFileListBox chokes if the filename ends on a '.' }
  143.         if FileName[len] = '.' then Dec(len);
  144.         FileListBox1.FileName := FileName
  145.       end
  146.     end
  147.   end
  148.   else
  149.     MessageDlg('No file selected', mtError, [mbOk], 0)
  150. end;
  151.  
  152. procedure TMainForm.UUEncodeButtonClick(Sender: TObject);
  153. var CallBackProc: TCallBack;
  154.     FileName: String;
  155.     Len: Byte absolute FileName;
  156.     OutFileName: String[13];
  157.     OutLen: Byte absolute OutFileName;
  158. begin
  159.   if FileListBox1.FileName <> '' then
  160.   begin
  161.     OutFileName := ChangeFileExt(ExtractFileName(FileListBox1.FileName),'.UUE') + #0;
  162.     FileName := FileListBox1.FileName + #0;
  163.     try
  164.       try
  165.         Gauge1.Progress := 0;
  166.         CallBackProc := CallBack;
  167.         if Sender = UUEncodeButton then
  168.           UUEncoder(@FileName[1],@OutFileName[1],644,False,CallBackProc)
  169.         else { Sender = UUDecodeButton }
  170.           UUDecoder(@FileName[1],CallBackProc)
  171.       except
  172.         on E: Exception do
  173.           MessageDlg(E.Message, mtError, [mbOk], 0)
  174.       end;
  175.     finally
  176.       FileListBox1.Directory := '.';
  177.       FileListBox1.Directory := DirectoryOutLine1.Directory; { rescan }
  178.       Dec(OutLen);
  179.       FileListBox1.FileName := OutFileName
  180.     end
  181.   end
  182.   else
  183.     MessageDlg('No file selected', mtError, [mbOk], 0)
  184. end;
  185.  
  186. procedure TMainForm.Button1Click(Sender: TObject);
  187. begin
  188.   MessageDlg('Read the accompanying article in The Delphi Magazines'#13#10+
  189.              'issues #4/#5 and #6 for more in-depth information about'#13#10+
  190.              '16- and 32-bit Delphi Efficiency.',
  191.               mtInformation,[mbOK],0)
  192. end;
  193.  
  194. end.
  195.  
  196.